﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NeuralStock.DomainService.Interfaces;
using NeuralStock.Entities;
using NeuralStock.Tools;

namespace NeuralStock.DomainService.Implementation
{
    public class GpwCompanyIndicatorsImportService : BaseService, IGpwCompanyIndicatorsImportService
    {
        ICompanyService companyService;

        public GpwCompanyIndicatorsImportService(ICompanyService companyService)
        {
            this.companyService = companyService;
        }

        public void ImportData()
        {
            var data = ReadData();

            foreach (var item in data)
            {
                if (companyService.Get(item.CompanyName) != null)
                {
                    companyService.Update(item.CompanyName, item.NumberOfShares, item.Sector, item.PE, item.PBV);
                }
                else
                {
                    companyService.Create(item.CompanyName);
                    companyService.Update(item.CompanyName, item.NumberOfShares, item.Sector, item.PE, item.PBV);
                }
            }
        }

        public List<GpwCompanyIndicatorsData> ReadData()
        {
            GpwCompanyIndicatorsDownloader downloader = new GpwCompanyIndicatorsDownloader();
            return downloader.GetData();
        }
    }
}
